import React, { Component } from 'react'
import store from '../redux/store'
import { jiaAction, jiaAsyncAction} from '../redux/count_actios'
export default class Count extends Component {
  state = {
    sum: 0
  }
  jia = () => {
    // const { sum } = this.state
    const { value } = this.numberNode

    // console.log(sum, value);
    // this.setState({
    //   sum: sum + value*1
    // })

    // const action = {
    //   type: 'jia',
    //   data: parseInt(value)
    // }

    store.dispatch(jiaAction(value*1, 1000))
   }
 
  asyncJia = () => { 
    // const { sum } = this.state
    const { value } = this.numberNode
    // console.log(sum, value);
    // setTimeout(() => { 
    //   this.setState({
    //     sum: sum + value*1
    //   })
    // }, 1000)
    
    store.dispatch(jiaAsyncAction(value*1, 1000))
  }
  render() {
    return (
      <div>
        <hr />
        <h1>Redux学习</h1>
        {/* <h4>求和：{ this.state.sum }</h4> */}
        <h4>求和：{ store.getState() }</h4>
        <select ref={c => this.numberNode = c }>
          <option value="1">1</option>
          <option value="2">2</option>
        </select>
        <button onClick={this.jia}>+</button>
        <button onClick={this.asyncJia}>异步+</button>
      </div>
    )
  }
}
